/*
 * Copyright (c) 2018, apexes.net. All rights reserved.
 *
 *         http://www.apexes.net
 *
 */
package net.apexes.demo.codegen.ormlite.column.base;

import net.apexes.commons.ormlite.Column;
import net.apexes.commons.ormlite.Table;
import net.apexes.demo.codegen.entity.enums.StatusFlag;
import net.apexes.demo.codegen.entity.base.EntityBase;

/**
 * 
 * @author <a href="mailto:hedyn@foxmail.com">HeDYn</a>
 *
 * @param <T>
 */
public abstract class QEntityBase<T extends EntityBase> extends Table<T> {

    public final Column id = field("id").id().varchar(22).build();

    public final Column statusFlag = field("statusFlag").enumeString(StatusFlag.class, 1).notNull().build();

    public final Column version = field("version").varchar(22).notNull().build();

    public final Column crtWho = field("crtWho").varchar(22).notNull().build();

    public final Column crtTime = field("crtTime").localDateTime().notNull().build();

    public final Column updWho = field("updWho").varchar(22).build();

    public final Column updTime = field("updTime").localDateTime().build();
    
    /**
     * 
     * @param dataClass
     */
    protected QEntityBase(Class<T> dataClass) {
        super(dataClass, true);
    }

    /**
     * 
     * @param dataClass
     * @param tableName
     */
    protected QEntityBase(Class<T> dataClass, String tableName) {
        super(dataClass, true, tableName);
    }

    @Override
    public Object getFieldValue(T instance, String fieldName) {
        switch (fieldName) {
            case "id":
                return instance.getId();
            case "statusFlag":
                return instance.getStatusFlag();
            case "version":
                return instance.getVersion();
            case "crtTime":
                return instance.getCrtTime();
            case "crtWho":
                return instance.getCrtWho();
            case "updTime":
                return instance.getUpdTime();
            case "updWho":
                return instance.getUpdWho();
            default:
                return super.getFieldValue(instance, fieldName);
        }
    }

    @Override
    public void setupFieldValue(T instance, String fieldName, Object value) {
        switch (fieldName) {
            case "id":
                instance.setId((java.lang.String) value);
                break;
            case "statusFlag":
                instance.setStatusFlag((net.apexes.demo.codegen.entity.enums.StatusFlag) value);
                break;
            case "version":
                instance.setVersion((java.lang.String) value);
                break;
            case "crtTime":
                instance.setCrtTime((java.time.LocalDateTime) value);
                break;
            case "crtWho":
                instance.setCrtWho((java.lang.String) value);
                break;
            case "updTime":
                instance.setUpdTime((java.time.LocalDateTime) value);
                break;
            case "updWho":
                instance.setUpdWho((java.lang.String) value);
                break;
            default:
                super.setupFieldValue(instance, fieldName, value);
                break;
        }
    }

}
